import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'

import pxtorem from 'postcss-pxtorem'; 
import { VantResolver } from '@vant/auto-import-resolver';
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    AutoImport({
      resolvers: [VantResolver(),ElementPlusResolver()]
    }),
    Components({
      resolvers: [VantResolver(),ElementPlusResolver()]
    })
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    }
  },
  server: {
    proxy: {
      // '/api': {
      //   target: 'http://172.27.6.139',
      //   changeOrigin: true
      // }
      '/api': {
        target: 'http://wq.bwstudent.com:7999',
        changeOrigin: true,
        rewrite: (path) => path.replace('/api', '')
      }
    }
  },
  css: {
    postcss: {
      plugins: [
        pxtorem({
           rootValue: 37.5, //手机设计稿宽度为375px的
           propList: ['*'], //属性的选择器，*表示通用
           exclude: /web/i, //忽略web下的所有文件
           selectorBlackList: ['.a-'] // 过滤掉.a- 开头的class，不进行rem转换
        }),
      ]
    }
  }
})
